package de.l3s.forgetit.services.schema;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;

@XmlRootElement(name = "pimo-actions")
public class PIMOLog implements Log {

	private int total;
	private PIMOActions actions;
	private MetaData metaData;
	
	public PIMOLog() {
		total = 0;
		actions = new PIMOActions();
		metaData = new MetaData();
	}
	
	@XmlAttribute(name = "number", required = true)
	@XmlSchemaType(name = "int")
	public int getTotal() {
		return total;
	}

	@XmlElement(name = "actions", type = PIMOActions.class)
	public PIMOActions getActions() {
		return actions;
	}

	@XmlElement(name = "extra", type = MetaData.class)
	public MetaData getMetaData() {
		return metaData;
	}

	public static PIMOLog example() {
		PIMOLog log = new PIMOLog();		
		
		PIMOAction a1 = new PIMOAction();
		a1.setUri("urn:nop:1383095769689:552331");
		a1.setLabel("opened by iPad");
		a1.setUserUri("pimo:1360234537404:8");
		a1.setType("view");
		a1.setTimestamp("2013-10-30 02:16:09");
		a1.setResource("Webpage", "master Hadoop Map/Reduce Administration", "http://hadoop.kbs.uni-hannover.de:50030/jobdetails.jsp?jobid=job_201310230155_0081&refresh=30");
		
		MetaData d1 = a1.getMetaData();
		d1.addPair("document type", "Webpage");
		d1.addPair("referrer", "http://hadoop.kbs.uni-hannover.de:50030/jobdetails.jsp?jobid=job_201310230155_0081&refresh=30");
		
		PIMOAction a2 = new PIMOAction();
		a2.setUri("urn:nop:1383226192378:978404");
		a2.setLabel("opened by iPad");
		a2.setUserUri("pimo:1360234537404:8");
		a2.setTimestamp("2013-10-31 14:29:52");
		a2.setType("view");
		a2.setResource("Document", "Hadoop Map/Reduce documents", "file:///home/tuan/hadoop-1.0.4/bin/hadoop");
		
		MetaData d2 = a1.getMetaData();
		d2.addPair("action object type", "bin file");
		
		log.getActions().addAction(a1);
		log.getActions().addAction(a2);		
		return log;
	}
	
}
